﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MediaManager
{
    public partial class Splash : Form
    {
        private string sInfo = "";
        Rectangle rectangle;
        public Splash()
        {
            InitializeComponent();
            this.rectangle = new Rectangle(0, 0, this.Width, this.Height);
        }
        public string LoadInformation
        {
            get
            {
                return this.sInfo;
            }
            set
            {
                this.sInfo = value;
                this.Refresh();
            }
        }
        protected Color beginColor = Color.FromArgb(113, 173, 255);
        protected Color endColor = Color.FromArgb(0, 69, 162);
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            OnPaint(e);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            //绘制背景
           // DrawBack(e.Graphics);

            this.DrawString(e.Graphics, this.rectangle, this.sInfo, System.Drawing.Color.Red);
        }

        protected virtual void DrawBack(Graphics g)
        {
            Pen pen = new Pen(Color.Black, 1);


            float redStep = (float)(beginColor.R - endColor.R) / this.Height;
            float greenStep = (float)(beginColor.G - endColor.G) / this.Height;
            float blueStep = (float)(beginColor.B - endColor.B) / this.Height;

            float R = beginColor.R;
            float G = beginColor.G;
            float B = beginColor.B;

            for (int i = 0; i < this.Height; i++)
            {
                if (R > 255) { R = 255; }
                if (R < 0) { R = 0; }
                if (G > 255) { G = 255; }
                if (G < 0) { G = 0; }
                if (B > 255) { B = 255; }
                if (B < 0) { B = 0; }

                pen.Color = Color.FromArgb((int)R, (int)G, (int)B);
                g.DrawLine(pen, 0, i, this.Width, i);

                R -= redStep;
                G -= greenStep;
                B -= blueStep;
            }
        }

        /// <summary>
        /// 绘制文本新到指定区域
        /// </summary>
        /// <param name="e">绘图面对象</param>
        /// <param name="rectangle">区域</param>
        /// <param name="text">绘制文本</param>
        /// <param name="textColor">文本颜色</param>
        /// <param name="stringAlignment">文本水平对齐方式</param>
        protected void DrawString(Graphics e, Rectangle rectangle, string text, Color textColor)
        {
            SolidBrush drawBrush = new SolidBrush(textColor);
            // Set format of string.
            StringFormat drawFormat = new StringFormat();
            drawFormat.FormatFlags = StringFormatFlags.NoClip;
            drawFormat.LineAlignment = StringAlignment.Center;
            drawFormat.Alignment = StringAlignment.Center;
            // Draw string to screen.
            e.DrawString(text, new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))), drawBrush, rectangle, drawFormat);
        }
    }
}
